function eatOne(match, amount, unit) {
  amount = Number(amount) - 1;
  if (amount == 1) {
    unit = unit.slice(0, unit.length - 1);
  }
  else if (amount == 0) {
    unit = unit + "s";
    amount = "no";
  }
  return amount + " " + unit;
}

var stock = "1 lemon, 2 cabbages, and 101 eggs";
stock = stock.replace(/(\d+) (\w+)/g, eatOne);
document.write(stock);


var slash = /\//;
document.write("AC/DC".search(slash));

var digitSurroundedBySpace = /\s\d\s/;
document.write("1a 2 3d".search(digitSurroundedBySpace));


